package org.jiajie.designpatterndemo.strategy.geek;

import java.util.HashMap;
import java.util.Map;

/**
 * 根据type创建策略的逻辑抽离出来，放到工厂类中
 * @author jay
 */
public class StrategyFactory {
    private static final Map<String, Strategy> strategies = new HashMap<>();

    static {
        strategies.put("A", new ConcreteStrategyA());
        strategies.put("B", new ConcreteStrategyA());
    }

    public static Strategy getStrategy(String type){
        if (type == null || type.isEmpty()) {
            throw new IllegalArgumentException("type should not be empty.");
        }
        return strategies.get(type);
    }
}
